package com.tetris.view;

import java.awt.event.MouseAdapter;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import static com.tetris.util.Constants.*;

public class ScorePanel extends JPanel {

    private static final long serialVersionUID = 1L;
    private JLabel levelLabel;
    private JLabel scoreLabel;
    private JLabel totalLabel;
    private JLabel twoRowsLabel;
    private JLabel threeRowsLabel;
    private JLabel fourRowsLabel;
    private JButton controllButton;

    public ScorePanel(){
        super();
        this.setSize(200, CELL_Size*GAME_HEIGHT);
        addText();
    }


    private void addText(){
        this.setLayout(null);// 设置空布局，即绝对布局
        Font font = new Font("微软雅黑", Font.PLAIN, 15);
        
        // 消除一行10分，连续消除两行得分30分，连续消除三行得分60分，连续消除四行得分100分
        levelLabel = new JLabel("当前难度：简单");
        levelLabel.setSize(200, 100);
        levelLabel.setBounds(10, 10, 180, 50);
        levelLabel.setFont(font);
        levelLabel.setToolTipText("超过 100 分难度自动升级到一般，超过 500 分难度自动升级到困难");

        scoreLabel = new JLabel("当前分数：0");
        scoreLabel.setSize(200, 100);
        scoreLabel.setBounds(10, 40, 180, 50);
        scoreLabel.setFont(font);
        scoreLabel.setToolTipText("一次消除一行 10 分，一次消除两行得分 30 分，一次消除三行得分 60 分，一次消除四行得分 100 分");

        totalLabel = new JLabel("消除总行数：0"); 
        totalLabel.setSize(200, 100);
        totalLabel.setBounds(10, 70, 180, 50);
        totalLabel.setFont(font);

        twoRowsLabel = new JLabel("连续消除两行次数：0");
        twoRowsLabel.setSize(200, 100);
        twoRowsLabel.setBounds(10, 100, 180, 50);
        twoRowsLabel.setFont(font);

        threeRowsLabel = new JLabel("连续消除三行次数：0");
        threeRowsLabel.setSize(200, 100);
        threeRowsLabel.setBounds(10, 130, 180, 50);
        threeRowsLabel.setFont(font);

        fourRowsLabel = new JLabel("连续消除四行次数：0");
        fourRowsLabel.setSize(200, 100);
        fourRowsLabel.setBounds(10, 160, 180, 50);
        fourRowsLabel.setFont(font);

        controllButton = new JButton("开始游戏");
        controllButton.setSize(200, 80);
        controllButton.setFont(font);
        controllButton.setBounds(50, 300, 100, 40);
        
        this.add(levelLabel);
        this.add(scoreLabel);
        this.add(totalLabel);
        this.add(twoRowsLabel);
        this.add(threeRowsLabel);
        this.add(fourRowsLabel);
        this.add(controllButton);
    }


    public void updateText(int score, int linesCount, int line2Count, int line3Count, int line4Count){
        if(score>500){
            levelLabel.setText("当前难度：困难");
        } else if(score>100){
            levelLabel.setText("当前难度：一般");
        }
        totalLabel.setText("消除总行数：" + linesCount);
        scoreLabel.setText("当前分数：" + score);
        twoRowsLabel.setText("连续消除两行次数：" + line2Count);
        threeRowsLabel.setText("连续消除三行次数：" + line3Count);
        fourRowsLabel.setText("连续消除四行次数：" + line4Count);
    }

    public void bindControllButtonAction(MouseAdapter m){
        controllButton.addMouseListener(m);
    }


	public void bindControllButtonAction(Object m) {
    }
    
    public void changeControllButtonText(String text){
        controllButton.setText(text);
    }

    public void controllButtonFocus(){
        controllButton.requestFocus();
    }

}